#!/usr/bin/env python
# encoding: utf-8

"""
@version: ??
@author: rourou 
@license: MIT 
@software: PyCharm Community Edition
@file: hw_server.py.py
@time: 2018/1/23 下午3:02
"""

import time
from concurrent import futures

import grpc
import hw_pb2, hw_pb2_grpc


_ONE_DAY_IN_SECONDS = 60 * 60 * 24


class Greeter(hw_pb2_grpc.GreeterServicer):
    def SayHello(self, request, context):
        return hw_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    hw_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    server.add_insecure_port('[::]:50051')
    server.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)


if __name__ == "__main__":
    serve()
